<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <script>
    var obj = {
      name: "liss",
      x: {
        y: {
          z: {
            f: 13,
          },
        },
      },
      address: "henan",
    };

    var obj2 = Object.assign(obj)
    console.log(obj2);

    //实现浅克隆
    // let newobj = {
    //   ...obj,
    // };
    // let newobj = JSON.parse(JSON.stringify(obj));
    // console.log(obj, newobj);

    //实现深克隆

    // function deepClone(obj) {
    //   var newobj = obj instanceof Array ? [] : {};
    //   for (var item in obj) {
    //     if (obj.hasOwnProperty(item)) {
    //       var temple =
    //         typeof obj[item] == "object" ? deepClone(obj[item]) : obj[item];
    //       newobj[item] = temple;
    //     }
    //   }
    //   return newobj;
    // }
    // var newobj = deepClone(obj);
    // console.log(obj, newobj);
  </script>
</body>

</html>